package cn.blog.service.front;

import java.util.ArrayList;
import java.util.List;

import cn.blog.dao.conn.ParamSet;
import cn.blog.dao.front.ArtilceDao;
import cn.blog.dao.front.ComDao;
import cn.blog.dao.front.UserDao;
import cn.blog.entity.addBean.BlogArtInfo;
import cn.blog.entity.origin.Article;
import cn.blog.entity.origin.User;

public class MainService {
	private UserDao userDao;
	private ArtilceDao artDao;
	private ComDao comDao;

	public MainService() {
		userDao = new UserDao();
		artDao = new ArtilceDao();
		comDao = new ComDao();
	}
	
	/**
	 * 根据用户id获取所有用户信息
	 * 
	 * @return 用户对象
	 */
	public User getUser(int userId) {
		return userDao.getUser(userId);
	}
	
	/**
	 * 根据用户编号查找所有文章
	 * @param userId	用户编号
	 * @return	所有文章集合
	 */	
	public List<BlogArtInfo> getArticle(int userId) {
		List<Article> article = artDao.userArt(userId);
		List<BlogArtInfo> art = new ArrayList<>();
		for (int i = 0; i < article.size(); i++) {
			// 更具文章用户编号获取用户对象
			User user = userDao.getUser(article.get(i).getArtUserId());
			// 更具文章编号获取评论数
			int comNum = comDao.comNum(article.get(i).getArtId());
			BlogArtInfo text = new BlogArtInfo(article.get(i).getArtId(), article.get(i).getArtUserId(),
					article.get(i).getArtTitle(), article.get(i).getArtClassId(), article.get(i).getArtTime(),
					article.get(i).getArtRead(), article.get(i).getArtContext(), user.getName(), comNum);
			art.add(text);
		}
		return art;
	}
	
	
}
